package com.bls.cate.ui.fragment.me;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bls.cate.R;
import com.bls.cate.mvp.MVPBaseFragment;
import com.bls.cate.mvp.RequestResultState;
import com.facebook.drawee.view.SimpleDraweeView;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class MeFragment extends MVPBaseFragment<MeContract.View, MePresenter> implements MeContract.View {

    String url = "http://47.104.76.28:8080/CateService/Account?RequestMethod=Login&Phone=18366184127&Password=111111";
    @BindView(R.id.iv_header)
    SimpleDraweeView ivHeader;
    @BindView(R.id.tv_nickname)
    TextView tvNickname;
    @BindView(R.id.tv_my_attention_num)
    TextView tvMyAttentionNum;
    @BindView(R.id.btn_my_attention)
    RelativeLayout btnMyAttention;
    @BindView(R.id.btn_setting)
    RelativeLayout btnSetting;
    Unbinder unbinder;

    int id = 1;
    @BindView(R.id.temp_4)
    TextView temp4;
    @BindView(R.id.temp_7)
    TextView temp7;

    public static MeFragment newInstance(String param1, String param2) {
        MeFragment meFragment = new MeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        meFragment.setArguments(args);
        return meFragment;
    }

    @Override
    protected int initLayoutId() {
        return R.layout.fragment_me;
    }

    @Override
    protected void initFvb(View fragView) {
        super.initFvb(fragView);
        unbinder = ButterKnife.bind(this, fragView);
    }

    @Override
    protected void initOnDestroyView() {
        super.initOnDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.btn_my_attention)
    public void onBtnMyAttentionClicked() {
    }

    @OnClick(R.id.btn_setting)
    public void onBtnSettingClicked() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
//获取当前时间
        Date date = new Date(System.currentTimeMillis());
        temp4.setText("时间:" + simpleDateFormat.format(date));
        mPresenter.requestGetNetData(id, url, null, (HttpParams) null);
    }


    @Override
    public void onRequestNetResult(int requestId, RequestResultState requestNetState, String responseBody, Response response) {
        super.onRequestNetResult(requestId, requestNetState, responseBody, response);
        if (requestNetState == RequestResultState.onFinish) {
            if (requestId < 200000) {
                id = id + 1;
                mPresenter.requestGetNetData(id, url, null, (HttpParams) null);
            } else {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
//获取当前时间
                Date date = new Date(System.currentTimeMillis());
                temp7.setText("时间:" + simpleDateFormat.format(date));
            }
        }
    }
}
